#pragma once
// 进程任务生成文件
#include <iostream>
#include <unistd.h>
#include <unordered_map>
#include <string>
#include <vector>
#include <functional>

typedef std::function<void()> func;  // 返回类型(参数) - 包装器-包装函数对象

std::vector<func> callFunc;
std::unordered_map<int, std::string> desc;  // describe - 描述信息

// 定义任务
void readMySQL()
{
    std::cout << "sub process[" << getpid() << "] 执行访问数据库的任务" << std::endl;
}

void execuleUrl()
{
    std::cout << "sub process[" << getpid() << "] 执行url解析" << std::endl;
}

void unpack()
{
    std::cout << "sub process[" << getpid() << "] 执行数据解包任务" << std::endl;
}

void cal()
{
    std::cout << "sub process[" << getpid() << "] 执行加密任务" << std::endl;
}

void save()
{
    std::cout << "sub process[" << getpid() << "] 执行访问数据持久化任务" << std::endl;
}

void load()  // 装载，将上述任务装载到容器中方便进行调用
{
    // desc.insert()
    desc[callFunc.size()] = "readMySQL: 访问数据库";
    callFunc.push_back(readMySQL);

    desc[callFunc.size()] = "execuleUrl: url解析";
    callFunc.push_back(execuleUrl);

    desc[callFunc.size()] = "unpack: 数据解包";
    callFunc.push_back(unpack);

    desc[callFunc.size()] = "cal: 数据加密";
    callFunc.push_back(cal);

    desc[callFunc.size()] = "save: 数据持久化";
    callFunc.push_back(save);
}


int funcSize()
{
    return callFunc.size();
}